package com.bdqn.util.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 本类存储对redis的操作
 */
@Component
public class Reggie_Redis_Template {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 将用户的登录验证码存储至reids  (String类型)
     */
    public Integer saveYZM(String phone, Integer code) {
        try {
            String reid_key = Phone_generateRedisKey.redis_key(phone);
            stringRedisTemplate.opsForValue().set(reid_key, code.toString());
            return 1;
        } catch (Exception e) {
            return 0;
        }
    }

    /**
     * 通过手机号去取对应的验证码
     */
    public String getYZM(String phone) {
        String redis_key = Phone_generateRedisKey.redis_key(phone);
        return stringRedisTemplate.opsForValue().get(redis_key);
    }
}
